package jwebtester.business.beans;

import infrastructure.Scopes;

import java.util.List;

import jwebtester.business.services.SessionMapService;
import jwebtester.dal.provider.UserManagementDataProvider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import domain.entities.User;

@Component
@Scope(Scopes.Request)
public class UsersBean {
	@Autowired
	private transient UserManagementDataProvider dataProvider;

	@Autowired
	private transient SessionMapService sessionService;

	private transient List<User> users;

	private User selectedUser;

	public List<User> getUsers() {
		if (users == null) {
			loadUsers();
		}

		return users;
	}

	public User getSelectedUser() {
		return selectedUser;
	}

	public void setSelectedUser(final User selectedUser) {
		this.selectedUser = selectedUser;
	}
	
	private void loadUsers() {
		users = dataProvider.getUsers(sessionService.getCurrentOrganizationID());
	}
}
